{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "aa7fc0be-e699-4b8b-b1b4-7ce2d6afe59b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/tinker/bbserverless/DIC/WebServices'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "cwd = os.getcwd()\n",
    "cwd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80035530-4652-4de8-8048-71d5f57fb4a8",
   "metadata": {},
   "source": [
    "### 1. update ow actions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "30599e3d-1b01-4fee-9f1e-3975ecaafba9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/home/tinker/bbserverless/DIC/WebServices/openwhisk/python-code/cryptography',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openwhisk/python-code/hash',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openwhisk/python-code/Md5',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openwhisk/python-code/sort',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openwhisk/python-code/hello']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paths = []\n",
    "command_prefix = 'sh '\n",
    "for root, dirs, files in os.walk(cwd+'/openwhisk', topdown=False):\n",
    "        if 'action-update.sh' in files:\n",
    "            paths.append(root)\n",
    "\n",
    "paths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bd2de125-665d-443a-9890-4b7514c42554",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['ok: updated action cryptography-python\\n']\n",
      "['ok: updated action hash-python\\n']\n",
      "['ok: updated action md5-python\\n']\n",
      "['ok: updated action sort-python\\n']\n",
      "['updating: __main__.py (deflated 32%)\\n', 'updating: action-update.sh (deflated 16%)\\n', 'updating: helper.py (deflated 35%)\\n', 'updating: stranger.zip (stored 0%)\\n', 'ok: updated action hello-python\\n']\n"
     ]
    }
   ],
   "source": [
    "\n",
    "for p in paths:\n",
    "    os.chdir(p)\n",
    "    command = command_prefix+ 'action-update.sh'\n",
    "    rw = os.popen(command).readlines()\n",
    "    print(rw)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "943a903c-6dcd-496f-bd09-5a819a63f722",
   "metadata": {},
   "source": [
    "### 2. update kubeless actions "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0218eefd-85a7-4a6a-bc39-5cabe0eea57f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/home/tinker/bbserverless/DIC/WebServices/kubeless/go-code/hello',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/java-code/hash',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/java-code/md5',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/java-code/sort',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/java-code/hello',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/nodejs-code/hash',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/nodejs-code/md5',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/nodejs-code/sort',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/nodejs-code/hello',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/python-code/cryptography',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/python-code/hash',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/python-code/Md5',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/python-code/sort',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/kubeless/python-code/hello']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paths_kl = []\n",
    "command_prefix = 'sh '\n",
    "for root, dirs, files in os.walk(cwd+'/kubeless', topdown=False):\n",
    "        if 'invoke.sh' in files:\n",
    "            root = root.replace('./','')\n",
    "            paths_kl.append(root)\n",
    "\n",
    "paths_kl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "754a2762-3968-4a76-9194-1305bdfeb445",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n",
      "sh invoke.sh\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "for p in paths_kl:\n",
    "    os.chdir(p)\n",
    "    command = command_prefix+ 'invoke.sh'\n",
    "    print(command)\n",
    "    rw = os.popen(command).readlines()\n",
    "    print(rw)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d5900cc-8ea6-4102-b454-69d5e5039e6b",
   "metadata": {},
   "source": [
    "### 3. update openfaas actions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1d1d46a4-3773-49f9-b514-38a206d980a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/home/tinker/bbserverless/DIC/WebServices/openfaas/python-code',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openfaas/nodejs-code',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openfaas/go-code',\n",
       " '/home/tinker/bbserverless/DIC/WebServices/openfaas/java-code']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paths_of = []\n",
    "for root, dirs, files in os.walk(cwd+'/openfaas', topdown=False):\n",
    "        if 'openfaas.yml' in files:\n",
    "            paths_of.append(root)\n",
    "\n",
    "paths_of"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89a6163d-5bc9-47e8-8dfa-9bd479cf1f0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "for p in paths_of:\n",
    "    os.chdir(p)\n",
    "    command = command_prefix+ 'action_build.sh' \n",
    "    print(os.getcwd() + command)\n",
    "    rw = os.popen(command).readlines()\n",
    "    print(rw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "79964c75-f8f4-41a7-8bff-f9513854e6b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/tinker/bbserverless/DIC/WebServices/openfaas/python-codesh action_push.sh && sh action_deploy.sh\n",
      "[]\n",
      "/home/tinker/bbserverless/DIC/WebServices/openfaas/nodejs-codesh action_push.sh && sh action_deploy.sh\n",
      "[]\n",
      "/home/tinker/bbserverless/DIC/WebServices/openfaas/go-codesh action_push.sh && sh action_deploy.sh\n",
      "['\\x1b[33m[0] > Pushing md5-go [k.harbor.siat.ac.cn/openfaas/go-md5:1.0.0].\\n', '\\x1b[0mThe push refers to repository [k.harbor.siat.ac.cn/openfaas/go-md5]\\n']\n",
      "/home/tinker/bbserverless/DIC/WebServices/openfaas/java-codesh action_push.sh && sh action_deploy.sh\n",
      "['\\x1b[33m[0] > Pushing hello-java [k.harbor.siat.ac.cn/openfaas/java-hello:1.0.0].\\n', '\\x1b[0mThe push refers to repository [k.harbor.siat.ac.cn/openfaas/java-hello]\\n']\n"
     ]
    }
   ],
   "source": [
    "for p in paths_of:\n",
    "    os.chdir(p)\n",
    "    command = command_prefix+ 'action_push.sh && '  +command_prefix+ 'action_deploy.sh'\n",
    "    print(os.getcwd() + command)\n",
    "    rw = os.popen(command).readlines()\n",
    "    print(rw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "232540ae-e2c7-4637-aecb-9d24d86d541b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
